<template>
	<view class="page">
		 <view class="img-wrap">
		 	 <image :src="tempFilePath" mode="" class="face-img"></image>
		 </view>
		 <view class="tips">
		 	/*需要从手机相册上传*/
		 </view>
	
			 <view class="cancel-upLoad btn" @click="reselectrface">
			 	重新选择
			 </view>
			 <view class="upload btn" @click = "upLoadFace">
			 	确认上传
			 </view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tempFilePath:''
			}
		},
		onLoad(params){
			this.tempFilePath = params.tempFilePath;
			    
		},
		methods: {
			
			upLoadFace(){
				var userInfo = uni.getStorageSync("globalInfo");
				uni.showLoading();
				
				uni.uploadFile({
					url:this.serverUrl +'/user/uploadFace?qq=3316368400&userId='+userInfo.id,
					filePath:this.tempFilePath,
					name:'file',
					header:{
						"headerUserId":userInfo.id,
						"headerUserToken":userInfo.userUniqueToken
					},
					success:(res)=>{
						var data = JSON.parse(res.data);
					  if(data.status == 200){
					
						  uni.setStorageSync("globalInfo",data.data);
						  uni.navigateBack({
						  	delta:1
						  });
					  }else if(data.status == 502 || data.status == 500){
						  uni.showToast ({
							  title:res.data.msg,
							  image:"../../static/icon/error.png",
							  duration:1500
						  })
					  }
					},
					complete:()=>{
						uni.hideLoading()
					}
				})
			},
			reselectrface(){
				uni.chooseImage({
					count:0,
					sizeType:['compressed'],
					sourceType:['album'],
					success:(res)=>{
						console.log(res);
						var tempFilePath = res.tempFilePaths[0];
						     this.tempFilePath = tempFilePath;
					  
					}
				})
			}
		}
	}
</script>

<style>
    .page{
		display: flex;
		flex-direction: column;
		position: fixed;
		width: 100%;
		height: 100%;
		background-color: #000000;
		text-align: center;
		font-size:12px;
	}
	.img-wrap{
		height: 60%;
		padding: 100upx 60upx 0;
	}
	.tips{
		color:#F7F7F7;
	}
	.btn{
		position: fixed;
		bottom: 40upx;
		color: #F1F1F1;
		width: 180upx;
		height: 60upx;
		line-height: 60upx;
		border: 1px solid #fff;
	}
	.cancel-upLoad{
		left:10upx;
	}
	.upload{
		right:10upx;
	}
	.face-img{
		width: 100%;
	}
</style>
